home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / umich / telecomm / sticpsrc.lzh / SOURCE.ARC / SCC.H < prev    next >
Encoding:
C/C++ Source or Header  |  1990-08-14  |  7.0 KB  |  159 lines

  1. /* Definitions for Z8530 SCC driver */
  2. /* Initially for Atari ST - Goal is to replace all Z8530 drivers */
  3.  
  4. #ifdef ATARI_ST
  5. typedef unsigned char *ioaddr;    /* type definition for an 'io port address' */
  6. #define MAXSCC        7    /* maximal number of SCC chips supported */
  7. #define TPS        100    /* scctim() ticks per second (10ms) */
  8. #define RDREG(a)    (*(a))          /* read any input port */
  9. #define WRREG(a,v)    *(a) = v      /* write any output port */
  10. #define RDSCC(c,r)    (*c = r, *c)      /* read SCC register */
  11. #define WRSCC(c,r,v)    {*c = r; *c = v;} /* write SCC register */
  12.  
  13. #ifdef __TURBOC__
  14. static unsigned char dummy;
  15. #define VOID(x)        dummy = (x)    /* discard a value */
  16. #endif
  17. #endif
  18.  
  19. #ifdef MSDOS
  20. typedef int16 ioaddr;        /* type definition for an 'io port address' */
  21. #define MAXSCC        6    /* maximal number of SCC chips supported */
  22. #define TPS        sccinfo.tps    /* scctim() ticks, # is variable */
  23. # if ((defined(MSC) && defined(INLINE)) || (defined(__TURBOC__) && defined(inportb)))
  24. /* special delay construction only necessary when inline IN/OUT is used */
  25. #define RDREG(a)    (scc_delay(inportb(a))) /* read any input port */
  26. #define WRREG(a,v)    {outportb(a,v); scc_delay();} /* write any output port */
  27. #define RDSCC(c,r)    (outportb(c,r), scc_delay(), scc_delay(inportb(c))) /* read SCC reg */
  28. #define WRSCC(c,r,v)    {outportb(c,r); scc_delay(); outportb(c,v); scc_delay();} /* write SCC reg*/
  29. # else
  30. #define RDREG(a)    (inportb(a))        /* read any input port */
  31. #define WRREG(a,v)    {outportb(a,v);}    /* write any output port */
  32. #define RDSCC(c,r)    (outportb(c,r), inportb(c)) /* read SCC reg */
  33. #define WRSCC(c,r,v)    {outportb(c,r); outportb(c,v);} /* write SCC reg */
  34. # endif
  35.  
  36. #define EAGLE        0x01    /* hardware type for EAGLE card */
  37. #define PC100        0x02    /* hardware type for PC100 card */
  38. #define PRIMUS        0x04    /* hardware type for PRIMUS-PC (DG9BL) card */
  39. #define DRSI        0x08    /* hardware type for DRSI PC*Packet card */
  40. #endif
  41.  
  42. #ifndef VOID
  43. #define VOID(x)        (x)    /* not necessary for most compilers */
  44. #endif
  45.  
  46. struct sccinfo {
  47.     int init;        /* SCC driver initialized? */
  48.     int nchips;        /* Number of SCC chips in system */
  49.     int maxchan;        /* Highest valid channel number */
  50.     ioaddr iobase;        /* Base address of first SCC */
  51.     int space;        /* Spacing between subsequent SCCs */
  52.     int off[2];        /* Offset to A and B channel control regs */
  53.     int doff;        /* Offset from control to data register */
  54.     int ivec;        /* System interrupt vector number */
  55.     long clk;        /* PCLK/RTxC frequency in Hz */
  56.     int pclk;        /* flag to use PCLK (instead of RTxC) */
  57.     unsigned int hwtype;    /* special hardware type indicator */
  58.     int hwparam;        /* special hardware parameter */
  59. #ifdef MSDOS
  60.     unsigned int tps;    /* Timer interrupt frequency in Hz, when variable */
  61.     unsigned long ticks;    /* Timer ticks since startup */
  62. #endif
  63. };
  64. extern struct sccinfo sccinfo;
  65.  
  66. /* SCC channel control structure for AX.25 mode */
  67. struct scca {
  68.     struct mbuf *rbp;    /* Head of mbuf chain being filled */
  69.     struct mbuf *rbp1;    /* Pointer to mbuf currently being written */
  70.  
  71.     struct mbuf *sndq;    /* Encapsulated packets awaiting transmission */
  72.     struct mbuf *tbp;    /* Transmit mbuf being sent */
  73.  
  74.     unsigned int maxdefer;    /* Timer for CSMA defer time limit */
  75.  
  76.     unsigned int tstate;    /* Transmitter state */
  77. #define IDLE        0    /* Transmitter off, no data pending */
  78. #define DEFER        1    /* Receive Active - DEFER Transmit */
  79. #define KEYUP        2    /* Permission to keyup the transmitter */
  80. #define KEYWT        3    /* Transmitter switched on, waiting for CTS */
  81. #define ACTIVE        4    /* Transmitter on, sending data */
  82. #define FLUSH        5    /* CRC sent - attempt to start next frame */
  83. #define TAIL        6    /* End of transmission, send tail */
  84.  
  85.     unsigned char params[11]; /* Channel control parameters */
  86. #define TXDELAY        1    /* Transmit Delay 10 ms/cnt */
  87. #define PERSIST        2    /* Persistence (0-255) as a % */
  88. #define SLOTTIME    3    /* Delay to wait on persistence hit */
  89. #define TAILTIME    4    /* Delay after XMTR OFF */
  90. #define FULLDUP        5    /* Full Duplex mode 0=CSMA 1=DUP 2=ALWAYS KEYED */
  91. #define TNCSPECIF    6    /* reserved for KISS-TNC-specific parameters */
  92. #define WAITTIME    7    /* Waittime before any transmit attempt */
  93. #define MAXKEYUP    8    /* Maximum time to transmit (seconds) */
  94. #define MINTIME        9    /* Minimal offtime after MAXKEYUP timeout */
  95. #define IDLETIME    10    /* Maximum idle time in ALWAYS KEYED mode (seconds) */
  96. };
  97.  
  98. /* SCC channel structure. one is allocated for each attached SCC channel, */
  99. /* so 2 of these are allocated for each fully utilized SCC chip */
  100. struct sccchan {
  101.     /* interrupt handlers for 4 different IP's */
  102.     /* MUST BE first 4 elements of this structure, and MUST remain */
  103.     /* in the sequence Transmit-Status-Receive-Special */
  104.     void (*int_transmit)(); /* Transmit Buffer Empty interrupt handler */
  105.     void (*int_extstat)();    /* External/Status Change interrupt handler */
  106.     void (*int_receive)();    /* Receive Character Avail. interrupt handler */
  107.     void (*int_special)();    /* Special Receive Condition interrupt handler */
  108.  
  109.     /* don't insert anything before "ctrl" (see assembly interrupt handler) */
  110.     ioaddr ctrl;        /* I/O address of CONTROL register */
  111.     ioaddr data;        /* I/O address of DATA register for this channel */
  112.  
  113.     unsigned char wreg[16]; /* Copy of last written value in WRx */
  114.     unsigned char status;    /* Copy of R0 at last external interrupt */
  115.     unsigned char txchar;    /* Char to transmit on next TX interrupt */
  116.  
  117.     struct interface *iface;/* associated interface structure */
  118.     struct mbuf *rqueue;    /* queue of received frames ready to process */
  119.     void (*recv)();        /* function to call to process these */
  120.     unsigned int timercount;/* 10ms timer for AX.25 use */
  121.     int group;        /* group ID for AX.25 TX interlocking */
  122. #define NOGROUP        0    /* not member of any group */
  123. #define RXGROUP        0x100    /* if set, only tx when all channels clear */
  124. #define TXGROUP        0x200    /* if set, don't transmit simultaneously */
  125.  
  126.     union {
  127.         struct slip s;    /* control structure for SLIP use */
  128.         struct scca a;    /* control structure for AX.25 use */
  129.     } c;
  130.  
  131.     long speed;        /* Line speed, bps */
  132.     int flags;        /* Clockmode/special flags, see below */
  133. #define DIVIDER        0x01    /* External /32 divider for fulldup available */
  134. #define EXTCLOCK    0x02    /* External clock source on RTxC/TRxC */
  135. #define TX_INHIBIT    0x80    /* Transmit is not allowed when set */
  136.  
  137.     /* statistic information on this channel */
  138.     long rxints;        /* Receiver interrupts */
  139.     long txints;        /* Transmitter interrupts */
  140.     long exints;        /* External/status interrupts */
  141.     long spints;        /* Special receiver interrupts */
  142.  
  143.     long enqueued;        /* Packets actually forwarded */
  144.     long rxframes;        /* Number of Frames Actally Received */
  145.     long rxerrs;        /* CRC Errors or KISS errors */
  146.     unsigned int nospace;    /* "Out of buffers" */
  147.     unsigned int rovers;    /* Receiver Overruns */
  148. };
  149. extern struct sccchan *sccchan[];
  150. #define NULLCHAN    (struct sccchan *)0
  151.  
  152. /* Z8530 SCC Register access macros */
  153.  
  154. #define rd(scc,reg)    RDSCC((scc)->ctrl,(reg))
  155. #define wr(scc,reg,val) WRSCC((scc)->ctrl,(reg),((scc)->wreg[reg] = val))
  156. #define or(scc,reg,val) WRSCC((scc)->ctrl,(reg),((scc)->wreg[reg] |= val))
  157. #define cl(scc,reg,val) WRSCC((scc)->ctrl,(reg),((scc)->wreg[reg] &= ~(val)))
  158.  
  159.